package com.congee02.state;

import com.congee02.ThreadProvider;

/**
 * @author congee02
 * @date 2/1/2023 4:23 PM
 */
public class ThreadStateTest {

    public static void main(String[] args) throws InterruptedException {
        ThreadProvider provider = new CommonThread();
        Thread t = provider.thread();
        System.out.println(t.getName() + " 状态 " + t.getState());
        t.start();
    
        while (Thread.State.TERMINATED != t.getState()) {
            System.out.println(t.getName() + " 状态 " + t.getState());
            Thread.sleep(500);
        }

        System.out.println(t.getName() + " 状态 " + t.getState());
    }
    
}

class CommonThread implements ThreadProvider {

    @Override
    public void run() {
        while (true) {
            for (int i = 0 ; i  < 10 ; i ++ ) {
                System.out.println("Hi " + i);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            break;
        }
    }
}
